//
//  ClassifyViewController.m
//  livingDesign
//
//  Created by dlios on 15-1-28.
//  Copyright (c) 2015年 怡居. All rights reserved.
//

#import "ClassifyViewController.h"
#import "ClassifyDetailsViewController.h"
#import "ClassifyCell.h"

@interface ClassifyViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>


@property (nonatomic, retain)UICollectionView *collectionView;//界面视图
@property (nonatomic, retain)NSMutableArray *nameArr;//装名字的数组
@property (nonatomic, retain)NSMutableArray *pictureArr;//装图片的数组

@end

@implementation ClassifyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"分类";
    //装名字
    self.nameArr = [NSMutableArray arrayWithObjects:@"攻略",@"装修清单",@"家饰",@"迷你户型",@"小户型",@"地中海",@"宜家",@"现代",@"田园",@"美式",@"欧式",@"编辑精选",@"装修案例",@"客厅",@"玄关",@"卧室",@"儿童房",@"厨房",@"餐厅",@"卫浴间",@"阳台",@"书房",@"其他", nil];
    //初始化图片数组
    self.pictureArr = [NSMutableArray array];
   //装图片
    for (NSInteger i = 0; i < 23; i++) {
       [self.pictureArr addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%ld.png",i]]];
    }
    
    UICollectionViewFlowLayout *classVFL = [[UICollectionViewFlowLayout alloc] init];
    
    classVFL.itemSize = CGSizeMake(self.view.frame.size.width / 3 - 1, 150);//单个视图的大小
    classVFL.minimumInteritemSpacing = 0.1;//列间距
    classVFL.minimumLineSpacing = 1;//行间距
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:classVFL];
    self.collectionView.backgroundColor = [UIColor colorWithRed:140 green:148 blue:142 alpha:0.8];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    [self.view addSubview:_collectionView];
    [_collectionView release];
    [classVFL release];
    
    //提前注册
    [self.collectionView registerClass:[ClassifyCell class] forCellWithReuseIdentifier:@"livingDesign"];
    
    
    
    
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.nameArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ClassifyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"livingDesign" forIndexPath:indexPath];
    cell.contentView.backgroundColor = [UIColor whiteColor];
    cell.myLabel.text = [self.nameArr objectAtIndex:indexPath.row];
    cell.imageView.image = [self.pictureArr objectAtIndex:indexPath.row];
    return cell;
    
}

//点击内容跳转页面
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row < 11) {
        ClassifyDetailsViewController *classifyDVC = [[ClassifyDetailsViewController alloc] init];
        classifyDVC.stu1 = [self.nameArr objectAtIndex:indexPath.row];
        [self.navigationController pushViewController:classifyDVC animated:YES];
        [classifyDVC  release];
     
    }else if (indexPath.row == 11){
        
        ClassifyDetailsViewController *classifyDVC = [[ClassifyDetailsViewController alloc] init];
        classifyDVC.stu3 = [self.nameArr objectAtIndex:indexPath.row];
        [self.navigationController pushViewController:classifyDVC animated:YES];
        [classifyDVC release];
        
    }else{
        ClassifyDetailsViewController *classifyDVC = [[ClassifyDetailsViewController alloc] init];
        classifyDVC.stu2 = [self.nameArr objectAtIndex:indexPath.row];
        [self.navigationController pushViewController:classifyDVC animated:YES];
        [classifyDVC release];
    }
    
    
}


//内存管理
- (void)dealloc
{
    [_collectionView release];
    [_nameArr release];
    [_pictureArr release];
    [super dealloc];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
